//
//  TabBarController.m
//  Budejie
//
//  Created by 远成物流 on 2017/5/12.
//  Copyright © 2017年 陈梦佳. All rights reserved.
//

#import "TabBarController.h"
#import "NavgationController.h"
#import "EssenceController.h"
#import "FollowController.h"
#import "MeController.h"
#import "NewController.h"
#import "PlusController.h"
#import "TabbarItem.h"

@interface TabBarController ()

@end

@implementation TabBarController

/**
 只调用一次
 */
+(void)load{
    //设置tabbar
    UITabBarItem *item = [UITabBarItem appearance];
    
    [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor],NSFontAttributeName:[UIFont systemFontOfSize:13]} forState:UIControlStateNormal];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //1.添加子控制器
    [self addChildViewController];
    
    //2.设置tabBar上按钮内容
    [self setupTabbarButton];
    
    //3.自定义tabbar
    [self setupTabBar];
}


/**
 添加子控制器
 */
-(void)addChildViewController{
    //精华
    EssenceController *essence = [[EssenceController alloc] init];
    NavgationController *essenceNav = [[NavgationController alloc] initWithRootViewController:essence];
    [self addChildViewController:essenceNav];
    
    //新帖
    NewController *new = [[NewController alloc] init];
    NavgationController *newNav = [[NavgationController alloc] initWithRootViewController:new];
    [self addChildViewController:newNav];
    
    //关注
    FollowController *follow = [[FollowController alloc] init];
    NavgationController *followNav = [[NavgationController alloc] initWithRootViewController:follow];
    [self addChildViewController:followNav];
    
    //我
    MeController *me = [[MeController alloc] init];
    NavgationController *meNav = [[NavgationController alloc] initWithRootViewController:me];
    [self addChildViewController:meNav];
}


/**
 设置tabBar上按钮内容
 */
-(void)setupTabbarButton{
    UINavigationController *nav0 = self.childViewControllers[0];
    nav0.tabBarItem.title = @"精华";
    nav0.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"];
    nav0.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_essence_click_icon"];
    
    UINavigationController *nav1 = self.childViewControllers[1];
    nav1.tabBarItem.title = @"新帖";
    nav1.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"];
    nav1.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_new_click_icon"];
    
    UINavigationController *nav2 = self.childViewControllers[2];
    nav2.tabBarItem.title = @"关注";
    nav2.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"];
    nav2.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_friendTrends_click_icon"];
    
    UINavigationController *nav3 = self.childViewControllers[3];
    nav3.tabBarItem.title = @"我";
    nav3.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"];
    nav3.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_me_click_icon"];
}


/**
 自定义tabbar
 */
-(void)setupTabBar{
    TabbarItem *tabbar = [[TabbarItem alloc] init];
    [self setValue:tabbar forKey:@"tabBar"];
    
    tabbar.plusButtonClicked = ^(){
        
        PlusController *plus = [[PlusController alloc] init];
        NavgationController *nav = [[NavgationController alloc] initWithRootViewController:plus];
        [self presentViewController:nav animated:YES completion:nil];
    };
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
